﻿<UserControl x:Class="VH.View.AddCustomerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:model="clr-namespace:VH.Model;assembly=VH.Model"
             xmlns:resources="clr-namespace:VH.Resources;assembly=VH.Resources" xmlns:view="clr-namespace:VH.View"
             xmlns:userControls="clr-namespace:VH.UI.UserControls;assembly=VH.UI.UserControls"
             xmlns:controls="clr-namespace:VH.UI.UserControls.Controls;assembly=VH.UI.UserControls"
             mc:Ignorable="d"
             x:Name="page"
             FocusManager.FocusedElement="{Binding ElementName=txtFirstName}">
    <UserControl.InputBindings>
        <KeyBinding Key="Enter"
                    Command="{Binding SaveCommand}" />
        <KeyBinding Key="Escape"
                    Command="{Binding CancelCommand}" />
    </UserControl.InputBindings>
    <AdornerDecorator>
        <Grid>


            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="8" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" BorderThickness="0">
                    <Grid Margin="0,10,0,0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <!--<TextBlock Text="{x:Static  resources:TitleResources.AddNewCustomer}" Style="{StaticResource Heading2}"
                           Margin="0,0,0,8" />-->
                        <Grid Grid.Row="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="5" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="5" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="5" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="5" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="5" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="15" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <Label
                                Content="{x:Static  resources:LabelResources.FirstName}" />
                            <Grid
                                Grid.Column="2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <TextBox
                                    x:Name="txtFirstName"
                                    Text="{Binding Entity.FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
                                    Width="200" />
                            </Grid>

                            <Label
                                Grid.Row="2"
                                Content="{x:Static  resources:LabelResources.LastName}" />
                            <Grid
                                Grid.Row="2"
                                Grid.Column="2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <TextBox
                                    Width="200"
                                    Text="{Binding Entity.LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
                            </Grid>

                            <Label
                                Grid.Row="4"
                                Content="{x:Static  resources:LabelResources.Gender}" />
                            <Grid
                                Grid.Row="4"
                                Grid.Column="2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <ComboBox
                                    Width="150"
                                    SelectedValue="{Binding Entity.Gender, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                    view:VHAttachedProperties.BindEnumToItemSource="VH.Model.Gender, VH.Model" />
                            </Grid>

                            <Label
                                Grid.Row="6"
                                Content="{x:Static  resources:LabelResources.DOB}" />
                            <Grid
                                Grid.Row="6"
                                Grid.Column="2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <DatePicker
                                    SelectedDate="{Binding Entity.DOB, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                    Width="150" />
                            </Grid>

                            <Label
                                Grid.Row="8"
                                Content="{x:Static  resources:LabelResources.EMail}" />
                            <Grid
                                Grid.Row="8"
                                Grid.Column="2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <TextBox
                                    Grid.Row="8"
                                    Grid.Column="2"
                                    Width="300"
                                    Text="{Binding Entity.Email, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
                            </Grid>


                            <Grid
                                Grid.Row="10"
                                Grid.ColumnSpan="3"
                                HorizontalAlignment="Left">
                                <Grid.Resources>
                                    <DataTemplate DataType="{x:Type model:CustomerAddress}">
                                        <Border BorderBrush="{StaticResource AccentColorBlueBrush}" BorderThickness="0,0,0,1">

                                            <StackPanel Margin="4" Visibility="{Binding IsDeleted, Converter={userControls:BoolToVisibilityValueConverter IsNegateValue=True}}">
                                                <CheckBox IsChecked="{Binding IsSelected}"  ToolTip="{x:Static  resources:TooltipResources.CheckToDelete}"/>
                                        <Grid Margin="4" >
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="5" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="*" />
                                            </Grid.ColumnDefinitions>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto" />
                                                <RowDefinition Height="5" />
                                                <RowDefinition Height="Auto" />
                                                <RowDefinition Height="5" />
                                                <RowDefinition Height="Auto" />
                                                <RowDefinition Height="5" />
                                                <RowDefinition Height="Auto" />
                                                <RowDefinition Height="5" />
                                                <RowDefinition Height="Auto" />
                                            </Grid.RowDefinitions>
                                            <Label
                                        Content="{x:Static  resources:LabelResources.Address}" />
                                            <TextBox Grid.Column="1"
                                                     Grid.ColumnSpan="3"
                                             Margin="8,0,0,0"
                                             Text="{Binding Address, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, FallbackValue=''}"
                                             HorizontalAlignment="Left"
                                             Width="300"
                                             AcceptsReturn="True" VerticalContentAlignment="Top" Height="40" />

                                            <Label
                                        Grid.Row="2"
                                        Content="{x:Static  resources:LabelResources.City}" />
                                            <ComboBox
                                        Grid.Column="1"
                                        Grid.Row="2"
                                        Margin="8,0,0,0"
                                        Width="220"
                                        HorizontalAlignment="Left"
                                        ItemsSource="{Binding DataContext.CityCollection, ElementName=page, Mode=OneWay}"
                                        SelectedValue="{Binding City, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}">
                                                <ComboBox.ItemsPanel>
                                                    <ItemsPanelTemplate>
                                                        <VirtualizingStackPanel />
                                                    </ItemsPanelTemplate>
                                                </ComboBox.ItemsPanel>
                                            </ComboBox>
                                            
                                            <TextBox
                                                Grid.Column="3"
                                                Grid.ColumnSpan="2"
                                        Grid.Row="2"
                                                Visibility="{Binding IsOtherCity, Converter={userControls:BoolToVisibilityValueConverter}}"
                                                Text="{Binding OtherCity, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged }"/>

                                            <Label
                                        Grid.Row="4"
                                        Content="{x:Static  resources:LabelResources.State}" />
                                            <ComboBox
                                        Grid.Column="1"
                                        Grid.Row="4"
                                        Margin="8,0,0,0"
                                        Width="220"
                                        HorizontalAlignment="Left"
                                        ItemsSource="{Binding DataContext.StateCollection, ElementName=page, Mode=OneWay}"
                                        SelectedValue="{Binding State, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}">
                                                <ComboBox.ItemsPanel>
                                                    <ItemsPanelTemplate>
                                                        <VirtualizingStackPanel />
                                                    </ItemsPanelTemplate>
                                                </ComboBox.ItemsPanel>
                                            </ComboBox>

                                            <Label
                                        Grid.Row="4"
                                                 Grid.Column="3"
                                        Content="{x:Static  resources:LabelResources.Country}" />
                                            <ComboBox
                                        Grid.Column="4"
                                        Grid.Row="4"
                                        Margin="8,0,0,0"
                                        Width="220"
                                        HorizontalAlignment="Left"
                                        IsSynchronizedWithCurrentItem="True"
                                        ItemsSource="{Binding DataContext.CountryCollection, ElementName=page, Mode=OneWay}"
                                        SelectedValue="{Binding Country, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}">
                                                <ComboBox.ItemsPanel>
                                                    <ItemsPanelTemplate>
                                                        <VirtualizingStackPanel />
                                                    </ItemsPanelTemplate>
                                                </ComboBox.ItemsPanel>
                                            </ComboBox>
                                          

                                            <Label
                                        Grid.Row="6"
                                        Content="{x:Static  resources:LabelResources.ZipCode}" />
                                            <TextBox Grid.Column="1" Grid.Row="6"
                                             Margin="8,0,0,0"
                                             Width="180"
                                             HorizontalAlignment="Left"
                                             userControls:TextBoxMaskBehavior.Mask="Integer"
                                             MaxLength="15"
                                             Text="{Binding ZipCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
                                        </Grid>
                                            </StackPanel>
                                            </Border>
                                    </DataTemplate>
                                    <DataTemplate DataType="{x:Type model:CustomerPhone}">
                                        <Grid Margin="4" Visibility="{Binding IsDeleted, Converter={userControls:BoolToVisibilityValueConverter IsNegateValue=True}}">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="5" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="5" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="5" />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>


                                            <CheckBox IsChecked="{Binding IsSelected}" Margin="0,0,10,0" ToolTip="{x:Static  resources:TooltipResources.CheckToDelete}"/>

                                            <controls:VHLabel
                                                Grid.Column="1"
                                                AddEndingPunctuation="True"
                                                Content="{x:Static  resources:LabelResources.Type}" />

                                            <ComboBox
                                                Grid.Column="2"
                                                Width="75"
                                                HorizontalAlignment="Left"
                                                SelectedValue="{Binding PhoneType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
                                                view:VHAttachedProperties.BindEnumToItemSource="VH.Model.PhoneType, VH.Model" />

                                            <controls:VHLabel
                                                AddEndingPunctuation="True"
                                                Grid.Column="4"
                                                Content="{x:Static  resources:LabelResources.Number}" />

                                            <TextBox Grid.Column="5"
                                                     HorizontalAlignment="Left"
                                                     Width="110"
                                                     userControls:TextBoxMaskBehavior.Mask="Integer"
                                                     MaxLength="11"
                                                     Text="{Binding PhoneNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />

                                            <controls:VHLabel
                                                Grid.Column="7"
                                                AddEndingPunctuation="True"
                                                Content="{x:Static  resources:LabelResources.Relationship}" />

                                            <ComboBox
                                                Grid.Column="8"
                                                Width="120"
                                                HorizontalAlignment="Left"
                                                SelectedValue="{Binding ContactRelationship, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
                                                view:VHAttachedProperties.BindEnumToItemSource="VH.Model.Relationship, VH.Model" />

                                            <TextBox Grid.Column="10"
                                                     HorizontalAlignment="Left"
                                                     Width="100"
                                                     Visibility="{Binding IsContactRelationshipOther, Converter={userControls:BoolToVisibilityValueConverter}}"
                                                     Text="{Binding ContactRelationshipOther, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
                                        </Grid>
                                    </DataTemplate>
                                </Grid.Resources>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="5" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                               
                                <GroupBox
                                    MaxHeight="400"
                                    Width="670"
                                    HorizontalAlignment="Left"
                                    ScrollViewer.VerticalScrollBarVisibility="Auto"
                                    Style="{DynamicResource MetroGroupBox}">
                                    <GroupBox.Header>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{x:Static  resources:LabelResources.AddressDetails}"
                                                       Foreground="{StaticResource WhiteBrush}" />
                                            <userControls:ModernButton
                                                Margin="15,0,0,0"
                                                ControlHeight="22"
                                                ControlWidth="22"
                                                IconWidth="13"
                                                IconHeight="13"
                                                IconData="F1 M 35,19L 41,19L 41,35L 57,35L 57,41L 41,41L 41,57L 35,57L 35,41L 19,41L 19,35L 35,35L 35,19 Z "
                                                ToolTip="{x:Static resources:TooltipResources.ADD}"
                                                Command="{Binding AddAddressCommand}" />

                                            <userControls:ModernButton
                                                HorizontalAlignment="Right"
                                                ControlHeight="22"
                                                ControlWidth="22"
                                                IconWidth="13"
                                                IconHeight="13"
                                                IconData="F1 M 16,15L 32,15C 32.5523,15 32.75,17.25 32.75,17.25L 15.25,17.25C 15.25,17.25 15.4477,15 16,15 Z M 22.5,12.5L 25.5,12.5C 25.7761,12.5 26.5,13.2239 26.5,13.5C 26.5,13.7762 25.7761,14.5 25.5,14.5L 22.5,14.5C 22.2238,14.5 21.5,13.7762 21.5,13.5C 21.5,13.2239 22.2238,12.5 22.5,12.5 Z M 17.5,18L 30.5,18C 31.0523,18 31.5,18.4477 31.5,19L 30.5,34C 30.5,34.5523 30.0523,35 29.5,35L 18.5,35C 17.9477,35 17.5,34.5523 17.5,34L 16.5,19C 16.5,18.4477 16.9477,18 17.5,18 Z M 19,20L 19.25,33L 21,33L 20.75,20L 19,20 Z M 23,20L 23,33L 25,33L 25,20L 23,20 Z M 27.25,20L 27,33L 28.75,33L 29,20L 27.25,20 Z "
                                                Margin="5,0,0,0"
                                                ToolTip="{x:Static resources:TooltipResources.Delete}"
                                                Command="{Binding DeleteAddressCommand}" />
                                        </StackPanel>

                                    </GroupBox.Header>
                                    <ItemsControl
                                        ItemsSource="{Binding Entity.CustomerAddresseCollection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                                        <ItemsControl.Template>
                                            <ControlTemplate>
                                                <ScrollViewer x:Name="ScrollViewer" Padding="{TemplateBinding Padding}"
                                                              BorderThickness="0">
                                                    <ItemsPresenter />
                                                </ScrollViewer>
                                            </ControlTemplate>
                                        </ItemsControl.Template>
                                    </ItemsControl>
                                </GroupBox>
                                <GroupBox
                                    Grid.Row="2"
                                    Width="670"
                                    MaxHeight="180"
                                    HorizontalAlignment="Left"
                                    ScrollViewer.VerticalScrollBarVisibility="Auto"
                                    Style="{DynamicResource MetroGroupBox}">
                                    <GroupBox.Header>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{x:Static  resources:LabelResources.PhoneDetails}"
                                                       Foreground="{StaticResource WhiteBrush}" />
                                            <userControls:ModernButton
                                                Margin="15,0,0,0"
                                                ControlHeight="22"
                                                ControlWidth="22"
                                                IconWidth="13"
                                                IconHeight="13"
                                                IconData="F1 M 35,19L 41,19L 41,35L 57,35L 57,41L 41,41L 41,57L 35,57L 35,41L 19,41L 19,35L 35,35L 35,19 Z "
                                                ToolTip="{x:Static resources:TooltipResources.ADD}"
                                                Command="{Binding AddPhoneCommand}" />

                                            <userControls:ModernButton
                                                HorizontalAlignment="Right"
                                                ControlHeight="22"
                                                ControlWidth="22"
                                                IconWidth="13"
                                                IconHeight="13"
                                                IconData="F1 M 16,15L 32,15C 32.5523,15 32.75,17.25 32.75,17.25L 15.25,17.25C 15.25,17.25 15.4477,15 16,15 Z M 22.5,12.5L 25.5,12.5C 25.7761,12.5 26.5,13.2239 26.5,13.5C 26.5,13.7762 25.7761,14.5 25.5,14.5L 22.5,14.5C 22.2238,14.5 21.5,13.7762 21.5,13.5C 21.5,13.2239 22.2238,12.5 22.5,12.5 Z M 17.5,18L 30.5,18C 31.0523,18 31.5,18.4477 31.5,19L 30.5,34C 30.5,34.5523 30.0523,35 29.5,35L 18.5,35C 17.9477,35 17.5,34.5523 17.5,34L 16.5,19C 16.5,18.4477 16.9477,18 17.5,18 Z M 19,20L 19.25,33L 21,33L 20.75,20L 19,20 Z M 23,20L 23,33L 25,33L 25,20L 23,20 Z M 27.25,20L 27,33L 28.75,33L 29,20L 27.25,20 Z "
                                                Margin="5,0,0,0"
                                                ToolTip="{x:Static resources:TooltipResources.Delete}"
                                                Command="{Binding DeletePhoneCommand}" />
                                        </StackPanel>

                                    </GroupBox.Header>
                                    <ItemsControl
                                        ItemsSource="{Binding Entity.CustomerPhoneCollection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                                        <ItemsControl.Template>
                                            <ControlTemplate>
                                                <ScrollViewer x:Name="ScrollViewer" Padding="{TemplateBinding Padding}"
                                                              BorderThickness="0">
                                                    <ItemsPresenter />
                                                </ScrollViewer>
                                            </ControlTemplate>
                                        </ItemsControl.Template>
                                    </ItemsControl>
                                </GroupBox>

                                <!--<Grid Grid.Row="2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="5" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>

                                <Label
                                    Content="{x:Static  resources:LabelResources.PhoneType}" />

                                <ComboBox
                                    Grid.Column="1"
                                    Width="150"
                                    HorizontalAlignment="Left"
                                    SelectedValue="{Binding Entity.CustomerPhoneCollection[0].PhoneType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
                                    view:VHAttachedProperties.BindEnumToItemSource="VH.Model.PhoneType, VH.Model" />

                                <Label
                                    Grid.Row="2"
                                    Content="{x:Static  resources:LabelResources.PhoneNumber}" />

                                <TextBox Grid.Row="2" Grid.Column="1"
                                         HorizontalAlignment="Left"
                                         Width="180"
                                         userControls:TextBoxMaskBehavior.Mask="Integer"
                                         MaxLength="11"
                                         Text="{Binding Entity.CustomerPhoneCollection[0].PhoneNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
                            </Grid>-->


                            </Grid>


                        </Grid>
                    </Grid>
                </ScrollViewer>
                <Grid
                    HorizontalAlignment="Center"
                    Grid.Row="2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="10" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Button
                        Content="{x:Static  resources:ButtonResources.Save}"
                        Command="{Binding SaveCommand}" />
                    <Button
                        Content="{x:Static  resources:ButtonResources.Cancel}"
                        Grid.Column="2"
                        Command="{Binding CancelCommand}" />
                </Grid>
            </Grid>

        </Grid>
    </AdornerDecorator>
</UserControl>
